<template>
	<view>
		<h4>1. 按步填写完企业信息，直至出现数据采集中</h4>
		<h4>2. 等待下方出现<span style="color: #007aff;">采集成功 获取结果</span>后，点击即可获取</h4>
		<web-view v-if="authUrl" :fullscreen="false" :webview-styles="webviewStyles" :src="authUrl"
			style="width: 100%;height: 1200rpx;margin-top: 3px;"></web-view>
		<h4 v-show="result" type="primary" id="dbjz" @click="ljhq">采集成功 获取结果</h4>
	</view>
</template>

<script>
	import {
		getPayTaxesAuthUrl,
		getPayTaxes
	} from '@/api/jinjian.js'

	export default {
		data() {
			return {
				webviewStyles: {
					progress: {
						color: '#FF3333'
					}
				},
				authUrl: undefined,
				id: undefined,
				result: false
			}
		},
		onLoad(event) {
			this.id = event.id
			getPayTaxesAuthUrl(event.id).then(res => {

				console.log('---res---', res)
				if (res.code == 200) {
					let data = res.data
					// console.log('---res.data---', data)
					var taxAuthUrl = JSON.parse(data.taxAuthUrl)
					this.authUrl = taxAuthUrl.retdata.authUrl
				} else {
					this.$modal.msgError(res.msg)
				}
			})
		},
		mounted() {
			// 开始轮询结果
			var lxGather = window.setInterval(() => {
				getPayTaxes(this.id).then(res => {
					if (res.code == 200) {
						let msg = JSON.parse(res.msg)
						const rc = msg.data.resultCode
						if (rc == 3) {
							clearInterval(lxGather)
							this.result = true
						} else if (rc == 4) {
							clearInterval(lxGather)
							this.$modal.loading('采集失败')
						}
					}
				})
			}, 4000)
		},
		methods: {
			ljhq() {
				this.$tab.navigateTo('/pages/loading?id=' + this.id)
			}
		}
	}
</script>

<style lang="scss">
	h4 {
		margin-top: 5px;
		text-align: center;
	}

	#dbjz {
		position: absolute;
		bottom: 0;
		width: 100%;
		padding: 8px;
		background: #007aff;
		color: #fff;
	}
</style>